package com.zhouyer.study.dao;

import com.zhouyer.study.entity.AuthCode;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * 验证码Dao层接口
 *
 * @author zhouyao
 * @version 1.0
 */
public interface AuthCodeDao extends JpaRepository<AuthCode, Long> {

    /**
     * 查询数据库中该邮箱地址对应的最近⼀次的验证码记录
     *
     * @param email 邮箱地址
     * @return com.zhouyer.study.pojo.AutoCode
     * @author zhouyao
     */
    @Query(value = "select id,email,code,createtime,expiretime from zhouyer_auth_code where email = :email ORDER BY createtime DESC LIMIT 1", nativeQuery = true)
    AuthCode findLastAutoCode(@Param("email") String email);
}
